/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package interface_graphique;

import ClassesJava.Cour;
import ClassesJava.Filiere;
import static interface_graphique.MenuPrincipale.menu;
import java.util.*;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author ISMAYLOULABBIHI
 */
public class Filieres extends javax.swing.JFrame {

    Filiere listf;
    DefaultTableModel model = new DefaultTableModel();
    int idf, j;

    /**
     * Creates new form Filieres
     */
    public Filieres() {
        initComponents();
       setLocationRelativeTo(null);
        model.addColumn("Numéro");
        model.addColumn("Nom");
        model.addColumn("Niveau");
        tabfilires.setModel(model);
        listf = new Filiere();
        afficher();
        afficher(0);

    }

    // afficher les filiere dans la table
    public void afficher() {
        model.setRowCount(0);
        Vector<Filiere> res = new Vector();
        res = listf.getFilieres();
        for (int i = 0; i < res.size(); i++) {
            Object[] e = {res.get(i).getNum(), res.get(i).getNom(), res.get(i).getNiveau()};
            model.addRow(e);
        }

    }

    // afficher un filiere i dans les texte 
    public void afficher(int i) {
        idf = (int) model.getValueAt(i, 0);
        txtid.setText(model.getValueAt(i, 0).toString());
        txtnom.setText(model.getValueAt(i, 1).toString());
        txtniveau.setText(model.getValueAt(i, 2).toString());
    }
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel5 = new javax.swing.JLabel();
        txtnom = new javax.swing.JTextField();
        txtniveau = new javax.swing.JTextField();
        jLabel9 = new javax.swing.JLabel();
        JbtNouveau = new javax.swing.JButton();
        jBtModifier = new javax.swing.JButton();
        jBtDernierElement = new javax.swing.JButton();
        jScrollPane2 = new javax.swing.JScrollPane();
        tabfilires = new javax.swing.JTable();
        jLabel8 = new javax.swing.JLabel();
        jBtAjouter = new javax.swing.JButton();
        jBtSupprimer = new javax.swing.JButton();
        jBtSuivent = new javax.swing.JButton();
        jBtPressident = new javax.swing.JButton();
        jBtPremiereElement = new javax.swing.JButton();
        txtid = new javax.swing.JTextField();
        jLabel10 = new javax.swing.JLabel();
        jLabel11 = new javax.swing.JLabel();
        txtnum = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosed(java.awt.event.WindowEvent evt) {
                formWindowClosed(evt);
            }
        });
        getContentPane().setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        jLabel5.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/fil.png"))); // NOI18N
        getContentPane().add(jLabel5, new org.netbeans.lib.awtextra.AbsoluteConstraints(500, 80, 110, -1));
        getContentPane().add(txtnom, new org.netbeans.lib.awtextra.AbsoluteConstraints(210, 140, 170, 30));
        getContentPane().add(txtniveau, new org.netbeans.lib.awtextra.AbsoluteConstraints(210, 180, 170, 30));

        jLabel9.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/Capture5.PNG"))); // NOI18N
        jLabel9.setText("jLabel9");
        getContentPane().add(jLabel9, new org.netbeans.lib.awtextra.AbsoluteConstraints(40, 90, 110, 130));

        JbtNouveau.setBackground(new java.awt.Color(51, 102, 255));
        JbtNouveau.setFont(new java.awt.Font("Tempus Sans ITC", 3, 12)); // NOI18N
        JbtNouveau.setForeground(new java.awt.Color(255, 255, 255));
        JbtNouveau.setActionCommand("NOUVEAR");
        JbtNouveau.setLabel("Nouveau");
        JbtNouveau.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                JbtNouveauActionPerformed(evt);
            }
        });
        getContentPane().add(JbtNouveau, new org.netbeans.lib.awtextra.AbsoluteConstraints(40, 220, 110, 30));

        jBtModifier.setBackground(new java.awt.Color(51, 102, 255));
        jBtModifier.setFont(new java.awt.Font("Tempus Sans ITC", 3, 12)); // NOI18N
        jBtModifier.setForeground(new java.awt.Color(255, 255, 255));
        jBtModifier.setText("MODIFIER");
        jBtModifier.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBtModifierActionPerformed(evt);
            }
        });
        getContentPane().add(jBtModifier, new org.netbeans.lib.awtextra.AbsoluteConstraints(280, 220, 100, 30));

        jBtDernierElement.setBackground(new java.awt.Color(51, 102, 255));
        jBtDernierElement.setFont(new java.awt.Font("Tempus Sans ITC", 3, 12)); // NOI18N
        jBtDernierElement.setForeground(new java.awt.Color(255, 255, 255));
        jBtDernierElement.setText(">>");
        jBtDernierElement.setActionCommand("");
        jBtDernierElement.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBtDernierElementActionPerformed(evt);
            }
        });
        getContentPane().add(jBtDernierElement, new org.netbeans.lib.awtextra.AbsoluteConstraints(420, 190, 70, -1));

        tabfilires.setBorder(javax.swing.BorderFactory.createMatteBorder(1, 1, 1, 1, new java.awt.Color(0, 255, 204)));
        tabfilires.setFont(new java.awt.Font("Tempus Sans ITC", 3, 12)); // NOI18N
        tabfilires.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null}
            },
            new String [] {
                "Numéro ", "Nom", "Niveau"
            }
        ));
        tabfilires.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        tabfilires.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                tabfiliresMouseClicked(evt);
            }
        });
        jScrollPane2.setViewportView(tabfilires);

        getContentPane().add(jScrollPane2, new org.netbeans.lib.awtextra.AbsoluteConstraints(40, 280, 300, 140));

        jLabel8.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/Capture_1.PNG"))); // NOI18N
        jLabel8.setText("jLabel8");
        getContentPane().add(jLabel8, new org.netbeans.lib.awtextra.AbsoluteConstraints(40, 30, 330, -1));

        jBtAjouter.setBackground(new java.awt.Color(51, 102, 255));
        jBtAjouter.setFont(new java.awt.Font("Tempus Sans ITC", 3, 12)); // NOI18N
        jBtAjouter.setForeground(new java.awt.Color(255, 255, 255));
        jBtAjouter.setText("AJOUTER");
        jBtAjouter.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBtAjouterActionPerformed(evt);
            }
        });
        getContentPane().add(jBtAjouter, new org.netbeans.lib.awtextra.AbsoluteConstraints(160, 220, 110, 30));

        jBtSupprimer.setBackground(new java.awt.Color(51, 102, 255));
        jBtSupprimer.setFont(new java.awt.Font("Tempus Sans ITC", 3, 12)); // NOI18N
        jBtSupprimer.setForeground(new java.awt.Color(255, 255, 255));
        jBtSupprimer.setText("SUPPRIMER");
        jBtSupprimer.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBtSupprimerActionPerformed(evt);
            }
        });
        getContentPane().add(jBtSupprimer, new org.netbeans.lib.awtextra.AbsoluteConstraints(390, 220, -1, 30));

        jBtSuivent.setBackground(new java.awt.Color(51, 102, 255));
        jBtSuivent.setFont(new java.awt.Font("Tempus Sans ITC", 3, 12)); // NOI18N
        jBtSuivent.setForeground(new java.awt.Color(255, 255, 255));
        jBtSuivent.setText(">");
        jBtSuivent.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBtSuiventActionPerformed(evt);
            }
        });
        getContentPane().add(jBtSuivent, new org.netbeans.lib.awtextra.AbsoluteConstraints(420, 160, 70, -1));

        jBtPressident.setBackground(new java.awt.Color(51, 102, 255));
        jBtPressident.setFont(new java.awt.Font("Tempus Sans ITC", 3, 12)); // NOI18N
        jBtPressident.setForeground(new java.awt.Color(255, 255, 255));
        jBtPressident.setText("<");
        jBtPressident.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBtPressidentActionPerformed(evt);
            }
        });
        getContentPane().add(jBtPressident, new org.netbeans.lib.awtextra.AbsoluteConstraints(420, 130, 70, 30));

        jBtPremiereElement.setBackground(new java.awt.Color(51, 102, 255));
        jBtPremiereElement.setFont(new java.awt.Font("Tempus Sans ITC", 3, 12)); // NOI18N
        jBtPremiereElement.setForeground(new java.awt.Color(255, 255, 255));
        jBtPremiereElement.setText("<<");
        jBtPremiereElement.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBtPremiereElementActionPerformed(evt);
            }
        });
        getContentPane().add(jBtPremiereElement, new org.netbeans.lib.awtextra.AbsoluteConstraints(420, 100, 70, -1));
        getContentPane().add(txtid, new org.netbeans.lib.awtextra.AbsoluteConstraints(210, 100, 170, 30));

        jLabel10.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/redoit.png"))); // NOI18N
        jLabel10.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        jLabel10.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jLabel10MouseClicked(evt);
            }
        });
        getContentPane().add(jLabel10, new org.netbeans.lib.awtextra.AbsoluteConstraints(550, 0, -1, -1));

        jLabel11.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/quite.png"))); // NOI18N
        jLabel11.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        jLabel11.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jLabel11MouseClicked(evt);
            }
        });
        getContentPane().add(jLabel11, new org.netbeans.lib.awtextra.AbsoluteConstraints(590, 0, -1, -1));

        txtnum.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/fond_ecran_wallpaper_25.jpg"))); // NOI18N
        getContentPane().add(txtnum, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 0, 630, 470));

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void JbtNouveauActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_JbtNouveauActionPerformed
        // booton Nouveau
        txtid.setText("");
        txtnom.setText("");
        txtniveau.setText("");
    }//GEN-LAST:event_JbtNouveauActionPerformed

    private void jBtModifierActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBtModifierActionPerformed
        // booton Modifier
        int i;
        Filiere f;
        f = new Filiere(idf, txtnom.getText(), txtniveau.getText());
        i = f.modifier(f);
        if (i == 1) {
            afficher();
            javax.swing.JOptionPane.showMessageDialog(null, "Le filière est bien Modifier", "Modifier un Filiere", javax.swing.JOptionPane.INFORMATION_MESSAGE);
        } else {
            javax.swing.JOptionPane.showMessageDialog(null, "echec de Modifier le filière", "Modifier un Filiere", javax.swing.JOptionPane.INFORMATION_MESSAGE);
        }

    }//GEN-LAST:event_jBtModifierActionPerformed

    private void jBtAjouterActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBtAjouterActionPerformed
        // booton Ajouter
        int i;
        Filiere f;
        f = new Filiere(0, txtnom.getText(), txtniveau.getText());
        i = f.ajouter(f);
        if (i == 1) {
            afficher();
            javax.swing.JOptionPane.showMessageDialog(null, "Un nouveau filière est bien enregistré", "Ajouter un Filiere", javax.swing.JOptionPane.INFORMATION_MESSAGE);
            for(int r =0 ; r<4 ; r++){
                    for(int c =0 ; c<6 ; c++){
                        Cour cour = new Cour(f.getDerniereFiliere() , r , c );                        
                        cour.ajoutersCour(cour);
                    }
            }
        } else {
            javax.swing.JOptionPane.showMessageDialog(null, "echec d'ajouter nouveau filière", "Ajouter un Filiere", javax.swing.JOptionPane.INFORMATION_MESSAGE);
        }
    }//GEN-LAST:event_jBtAjouterActionPerformed

    //Afficher le Pressident Element de la table
    private void jBtPressidentActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBtPressidentActionPerformed
        if (j > 0) {
            j--;
            afficher(j);
        }
    }//GEN-LAST:event_jBtPressidentActionPerformed

    private void tabfiliresMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tabfiliresMouseClicked
        j = tabfilires.getSelectedRow();
        afficher(j);
    }//GEN-LAST:event_tabfiliresMouseClicked

    private void jBtSupprimerActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBtSupprimerActionPerformed
        //botton suppriler 
        int i;
        Filiere f;
        f = new Filiere(idf, txtnom.getText(), txtniveau.getText());
        i = f.supprimer(f);
        if (i == 1) {
            afficher();
            javax.swing.JOptionPane.showMessageDialog(null, "Un filière est bien Supprimer", "Supprimer un Filiere", javax.swing.JOptionPane.INFORMATION_MESSAGE);
        } else {
            javax.swing.JOptionPane.showMessageDialog(null, "echec de supprimer filière", "Supprimer un Filiere", javax.swing.JOptionPane.INFORMATION_MESSAGE);
        }
    }//GEN-LAST:event_jBtSupprimerActionPerformed

    //Afficher le Premiere Element de la table
    private void jBtPremiereElementActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBtPremiereElementActionPerformed
        j = 0;
        afficher(j);
    }//GEN-LAST:event_jBtPremiereElementActionPerformed
    //Afficher le Suivent Element de la table
    private void jBtSuiventActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBtSuiventActionPerformed
        if (j < tabfilires.getRowCount() - 1) {
            j++;
            afficher(j);
        }
    }//GEN-LAST:event_jBtSuiventActionPerformed
    //Afficher le Dernier Element du table
    private void jBtDernierElementActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBtDernierElementActionPerformed
        j = tabfilires.getRowCount() - 1;
        afficher(j);

    }//GEN-LAST:event_jBtDernierElementActionPerformed

    private void formWindowClosed(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosed
        menu.setVisible(true);
    }//GEN-LAST:event_formWindowClosed

    private void jLabel10MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jLabel10MouseClicked
        // TODO add your handling code here:
    }//GEN-LAST:event_jLabel10MouseClicked

    private void jLabel11MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jLabel11MouseClicked
        menu.setVisible(true);
        this.setVisible(false);
    }//GEN-LAST:event_jLabel11MouseClicked

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(Filieres.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(Filieres.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(Filieres.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(Filieres.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new Filieres().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton JbtNouveau;
    private javax.swing.JButton jBtAjouter;
    private javax.swing.JButton jBtDernierElement;
    private javax.swing.JButton jBtModifier;
    private javax.swing.JButton jBtPremiereElement;
    private javax.swing.JButton jBtPressident;
    private javax.swing.JButton jBtSuivent;
    private javax.swing.JButton jBtSupprimer;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JTable tabfilires;
    private javax.swing.JTextField txtid;
    private javax.swing.JTextField txtniveau;
    private javax.swing.JTextField txtnom;
    private javax.swing.JLabel txtnum;
    // End of variables declaration//GEN-END:variables
}
